using UnityEngine;

public class GuideTask : BaseTask
{
	public static GuideTask instance;

	private Vector3 despos;

	public Transform desobj;

	public int curstep;

	public bool[] stepflag;

	public bool[] showinfoflag;

	private bool disflag;

	private float resettime = 3f;

	private Camera maincam;

	private Vector3 UIscreenpos;

	private float dirflagoffset;

	private float scale_rate;

	private Vector3 curscreenpos;

	private bool showgunflag;

	private bool showmissileflag;

	private int step4_index;

	private AIController curaiplane;

	public override void MyUpdate()
	{
		if (FinishState)
		{
			return;
		}
		if (!stepflag[curstep])
		{
			switch (curstep)
			{
				case 0:
					step0();
					break;
				case 1:
					step1();
					break;
				case 2:
					step2();
					break;
				case 3:
					step3();
					break;
				case 4:
					step4();
					break;
			}
		}
		if (plane_smothfollow.instance.isdied)
		{
			UIController.instance.show_hitinfo_down("你将在 " + ((int)resettime + 1) + " 秒后复活");
			resettime -= Time.deltaTime;
			if (resettime <= 0f)
			{
				resettime = 3f;
				plane_smothfollow.instance.Reset_posrot();
				UIController.instance.show_hitinfo_down(string.Empty);
			}
		}
	}

	public void showUIflag(Vector3 despos)
	{
		dirflagoffset = 32f * GlobalInf.ratioReltoUI;
		curscreenpos = maincam.WorldToScreenPoint(despos);
		if (curscreenpos.x > 0f && curscreenpos.y > 0f && curscreenpos.x < (float)Screen.width && curscreenpos.y < (float)Screen.height && curscreenpos.z > 0f)
		{
			scale_rate = (2000f - Vector3.Distance(despos, maincam.transform.position)) / 2000f + 0.6f;
			if (scale_rate < 0.6f)
			{
				scale_rate = 0.6f;
			}
			if (scale_rate > 1f)
			{
				scale_rate = 1f;
			}
			UIController.instance.Des_flagshow(curscreenpos, istrue: true, scale_rate);
			UIController.instance.Des_dirshow(Vector3.zero, istrue: false);
			return;
		}
		scale_rate = (2000f - Vector3.Distance(despos, maincam.transform.position)) / 2000f + 0.4f;
		if (scale_rate < 0.4f)
		{
			scale_rate = 0.4f;
		}
		if (scale_rate > 0.6f)
		{
			scale_rate = 0.6f;
		}
		dirflagoffset *= scale_rate;
		UIController.instance.Des_flagshow(Vector3.zero, istrue: false);
		if (curscreenpos.z > 0f)
		{
			UIscreenpos = curscreenpos;
			if (UIscreenpos.x < 0f)
			{
				UIscreenpos.x = dirflagoffset;
			}
			if (UIscreenpos.x > (float)Screen.width)
			{
				UIscreenpos.x = (float)Screen.width - dirflagoffset;
			}
			if (UIscreenpos.y < 0f)
			{
				UIscreenpos.y = dirflagoffset;
			}
			if (UIscreenpos.y > (float)Screen.height)
			{
				UIscreenpos.y = (float)Screen.height - dirflagoffset;
			}
			UIController.instance.Des_dirshow(UIscreenpos, istrue: true, scale_rate);
			return;
		}
		UIscreenpos = curscreenpos;
		UIscreenpos.x = (float)Screen.width - UIscreenpos.x;
		UIscreenpos.y = (float)Screen.height - UIscreenpos.y;
		Vector3 vector = maincam.transform.InverseTransformPoint(despos);
		if (vector.x > 0f)
		{
			UIscreenpos.x = (float)Screen.width - dirflagoffset;
			if (UIscreenpos.y < 0f)
			{
				UIscreenpos.y = dirflagoffset;
			}
			if (UIscreenpos.y > (float)Screen.height)
			{
				UIscreenpos.y = (float)Screen.height - dirflagoffset;
			}
		}
		else
		{
			UIscreenpos.x = dirflagoffset;
			if (UIscreenpos.y < 0f)
			{
				UIscreenpos.y = dirflagoffset;
			}
			if (UIscreenpos.y > (float)Screen.height)
			{
				UIscreenpos.y = (float)Screen.height - dirflagoffset;
			}
		}
		UIController.instance.Des_dirshow(UIscreenpos, istrue: true, scale_rate);
	}

	public override void MyStart()
	{
		GameUIController.instance.gameguideui.stepstart();
		if (instance == null)
		{
			instance = this;
		}
		maincam = Camera.main;
		FinishState = false;
		timebegin = true;
		isSuccess = false;
		stoptime = 0f;
		one = false;
		two = false;
		three = false;
		four = false;
		AIPool.instance.creat_plane_random(plane_smothfollow.instance.m_Transform, 1, 0);
		AIPool.instance.DisableAllAI();
	}

	public override void MyEnd()
	{
		base.MyEnd();
		if (instance != null)
		{
			instance = null;
		}
		UIController.instance.Des_dirshow(Vector3.zero, istrue: false);
		UIController.instance.Des_flagshow(Vector3.zero, istrue: false);
		UnityVersionUtil.SetActiveRecursive(desobj.gameObject, state: false);
		GamePlayerprefs.instance.setgamefirst();
	}

	public void pausegame()
	{
		Time.timeScale = 0f;
	}

	public void resumegame()
	{
		Time.timeScale = 1f;
	}

	public void step0()
	{
		if (!showinfoflag[0])
		{
			showinfoflag[0] = true;
			UIController.instance.show_hitinfo("欢迎来到天空战斗机，\n让我们一起来学习如何飞行和战斗！");
			UIController.instance.hitinfo_appear();
			stoptime = 0f;
			Platform.flurryEvent_guide_first_game(0);
			GlobalInf.flyrange_AI = 8000;
		}
		stoptime += Time.deltaTime;
		if (stoptime > 3f)
		{
			stepflag[0] = true;
			curstep++;
		}
	}

	public void step1()
	{
		if (!showinfoflag[1])
		{
			showinfoflag[1] = true;
			UIController.instance.show_hitinfo("让飞机起飞！请按下加速按钮！");
			GameUIController.instance.gameguideui.step1();
			Platform.flurryEvent_guide_first_game(1);
		}
		if (PlaneMoveController.instance.accflagstate)
		{
			resumegame();
			if (PlaneMoveController.instance.speed >= 140f)
			{
				stepflag[1] = true;
				curstep++;
				resumegame();
				GameUIController.instance.gameguideui.disappear_finger();
			}
		}
		else
		{
			pausegame();
		}
	}

	public void step2()
	{
		if (!showinfoflag[2])
		{
			showinfoflag[2] = true;
			UIController.instance.show_hitinfo("推动操纵杆以起飞");
			GameUIController.instance.gameguideui.step2();
			pausegame();
			stoptime = 0f;
			disflag = false;
			Platform.flurryEvent_guide_first_game(2);
		}
		if (Joystick.joystickend.y < -0.5f && !disflag)
		{
			resumegame();
			GameUIController.instance.gameguideui.disappear_finger();
			GameUIController.instance.gameguideui.disappear_dir();
			UIController.instance.hitinfo_disappear();
			disflag = true;
		}
		stoptime += Time.deltaTime;
		if (stoptime > 6f)
		{
			stepflag[2] = true;
			curstep++;
		}
	}

	public void step3()
	{
		if (!showinfoflag[3])
		{
			showinfoflag[3] = true;
			UIController.instance.show_hitinfo("现在前往目标地点。\n它在小地图上显示");
			UIController.instance.hitinfo_appear();
			GameUIController.instance.gameguideui.step3();
			stoptime = 0f;
			disflag = false;
			despos = plane_smothfollow.instance.GetForwardpos();
			desobj.position = despos;
			UnityVersionUtil.SetActiveRecursive(desobj.gameObject, state: true);
			Platform.flurryEvent_guide_first_game(3);
		}
		stoptime += Time.deltaTime;
		if (stoptime > 4f)
		{
			if (!disflag)
			{
				UIController.instance.hitinfo_disappear();
				disflag = true;
			}
			else if (stoptime > 10f && Vector3.Distance(PlaneMoveController.instance.m_transform.position, despos) > 2000f)
			{
				stoptime = 0f;
				UIController.instance.hitinfo_appear();
				disflag = false;
			}
		}
		minimapcontroller.instance.show_taskflag(despos, isshow: true);
		showUIflag(despos);
		if (Vector3.Distance(plane_smothfollow.instance.plane_body.position, despos) < 100f)
		{
			minimapcontroller.instance.show_taskflag(despos, isshow: false);
			UnityVersionUtil.SetActiveRecursive(desobj.gameObject, state: false);
			UIController.instance.Des_dirshow(Vector3.zero, istrue: false);
			UIController.instance.Des_flagshow(Vector3.zero, istrue: false);
			if (!disflag)
			{
				UIController.instance.hitinfo_disappear();
			}
			stepflag[3] = true;
			curstep++;
		}
	}

	public void step4()
	{
		if (!showinfoflag[4])
		{
			showinfoflag[4] = true;
			UIController.instance.show_hitinfo("干得好！现在敌人来了，\n控制操纵杆瞄准敌人");
			UIController.instance.hitinfo_appear();
			stoptime = 0f;
			disflag = false;
			step4_index = 0;
			UIController.instance.ishavesingle = false;
			AIPool.instance.creat_plane_random(plane_smothfollow.instance.m_Transform, 1, 0);
			curaiplane = AIPool.instance.AIList[0];
			Platform.flurryEvent_guide_first_game(4);
		}
		stoptime += Time.deltaTime;
		if (stoptime > 4f)
		{
			if (!disflag)
			{
				UIController.instance.hitinfo_disappear();
				disflag = true;
			}
			else if (stoptime > 10f && Vector3.Distance(PlaneMoveController.instance.m_transform.position, despos) > 3000f)
			{
				stoptime = 0f;
				UIController.instance.show_hitinfo("控制操纵杆瞄准敌人，然后开火！");
				UIController.instance.hitinfo_appear();
				disflag = false;
			}
		}
		if (step4_index == 0)
		{
			if (plane_smothfollow.instance.curAI != null && !showgunflag)
			{
				showgunflag = true;
				GameUIController.instance.gameguideui.step4_gun();
				pausegame();
				stoptime = 0f;
				UIController.instance.show_hitinfo("点击机枪按钮并开火！");
				UIController.instance.hitinfo_appear();
				disflag = false;
			}
			if (showgunflag && plane_smothfollow.instance.machinegunFlag)
			{
				resumegame();
				step4_index++;
				GameUIController.instance.gameguideui.disappear_finger();
				Platform.flurryEvent_guide_first_game(5);
			}
		}
		if (step4_index == 1 && (float)curaiplane.health_con.CurrentHP / (float)curaiplane.health_con.MaxHP < 0.5f)
		{
			step4_index++;
			UIController.instance.ishavesingle = true;
		}
		if (step4_index == 2)
		{
			if (plane_smothfollow.instance.missileCurAi != null && !showmissileflag)
			{
				showmissileflag = true;
				GameUIController.instance.gameguideui.step4_missile();
				pausegame();
				stoptime = 0f;
				UIController.instance.show_hitinfo("点击导弹按钮并开火！");
				UIController.instance.hitinfo_appear();
				disflag = false;
			}
			if (showmissileflag && plane_smothfollow.instance.singlemissileFlag)
			{
				resumegame();
				step4_index++;
				GameUIController.instance.gameguideui.disappear_finger();
				Platform.flurryEvent_guide_first_game(6);
			}
		}
		if (curaiplane.isdie)
		{
			if (!disflag)
			{
				UIController.instance.hitinfo_disappear();
			}
			FinishState = true;
			isSuccess = true;
			stepflag[4] = true;
			curstep++;
			GameUIController.instance.gameguideui.disable();
		}
	}
}
